//
//  CourseDetailHeaderPax.m
//  HandheldELearn
//
//  Created by wsj2015 on 16/8/2.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "CourseDetailHeaderPax.h"
#import "HMSegmentedControl.h"
#import "UIImageView+UIActivityIndicatorForSDWebImage.h"

@implementation CourseDetailHeaderPax
{
    NSInteger _tag;
}
- (void)awakeFromNib {
 
    _tag = 100;
    self.lineHeght.constant = kScreenWidth/2;
    self.ratingVIew.userInteractionEnabled = NO;
    
    
}

- (IBAction)btnAction:(UIButton *)sender {
   
    if (_tag == sender.tag) {
        return;
    }
    UIButton *btn =[self.btnBgView viewWithTag:_tag];
    btn.selected = NO;
    sender.selected = !sender.selected;
     _tag = sender.tag;

    if (_tag == 100) {
       self.lineLeading.constant = 0;;
    }else{

        self.lineLeading.constant = kScreenWidth/2;;
    }
   
    [self setNeedsLayout];
    
    sender.titleLabel.layer.anchorPoint = CGPointMake(0, 0.5);
    [UIView animateWithDuration:.3f animations:^{
        [self layoutIfNeeded];
        sender.titleLabel.transform = CGAffineTransformScale(btn.transform, .6, .6);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:.3f animations:^{
          
            sender.titleLabel.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            
        }];
    }];
    if (self.changeSelectItem) {
        self.changeSelectItem(_tag -100);
    }
   

}
- (void)setModel:(HELCourseDetailModel *)model{
    _model = model;
    [self.mainPic setImageWithURL:[NSURL URLWithString:model.attachUrlShowMap.src] placeholderImage:[UIImage imageNamed:@"暂无图片.jpg"]usingActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    self.titleL.text = model.name;
    CGFloat f= [model.scoreAvg floatValue]/2;
    self.ratingVIew.value = f;
    
    self.ratingLabel.text = [NSString stringWithFormat:@"%.f分",[model.scoreAvg floatValue]];
    
  
    self.typeLabel.text =[NSString stringWithFormat:@"所属科室:%@",model.departmentName];
    
    if ([model.collectStatus isEqualToString:@"1"]) {
        self.collectBtn.selected = YES;
        
    }else{
     self.collectBtn.selected = NO;
    }
    
    
}


- (IBAction)collectAction:(UIButton *)sender {
    
    if (self.collectBlock) {
        self.collectBlock(sender);
    }
    
}

-(void)segmentedControlChangedValue:(HMSegmentedControl *)sender{
    
}
@end
